
package com.sausageking.client.consumer.gin;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.inject.client.assistedinject.GinFactoryModuleBuilder;
import com.google.gwt.place.shared.PlaceController;
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.sausageking.client.ConsumerService;
import com.sausageking.client.ConsumerServiceAsync;
import com.sausageking.client.MerchantService;
import com.sausageking.client.MerchantServiceAsync;
import com.sausageking.client.common.ClientUtil;
import com.sausageking.client.consumer.activity.MerchantPresenterImpl;
import com.sausageking.client.consumer.ui.DealView;
import com.sausageking.client.consumer.ui.DealViewImpl;
import com.sausageking.client.consumer.ui.MerchantView;
import com.sausageking.client.consumer.ui.MerchantViewImpl;
import com.sausageking.client.consumer.ui.RedeemDialogView;
import com.sausageking.client.consumer.ui.RedeemDialogViewImpl;
import com.sausageking.client.consumer.ui.StampDialogView;
import com.sausageking.client.consumer.ui.StampDialogViewImpl;
import com.sausageking.client.consumer.ui.resources.Resources;
import com.sausageking.client.mvp.AppActivityMapper;
import com.sausageking.shared.BaseUtil;

public abstract class BaseGinModule extends AbstractGinModule {

  abstract void addAppSpecficicConfig();

  @Override
  protected void configure() {
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    bind(ActivityMapper.class).to(AppActivityMapper.class).in(Singleton.class);
    bind(BaseUtil.class).to(ClientUtil.class);

    // common views
    bind(MerchantView.class).to(MerchantViewImpl.class);
    install(new GinFactoryModuleBuilder().implement(DealView.class,
        DealViewImpl.class).build(DealViewFactory.class));
    bind(StampDialogView.class).to(StampDialogViewImpl.class);
    bind(RedeemDialogView.class).to(RedeemDialogViewImpl.class);

    // common presenters
    bind(MerchantView.Presenter.class).to(MerchantPresenterImpl.class);
    addAppSpecficicConfig();
  }

  @Inject
  @Singleton
  @Provides
  ActivityManager provideActivityManager(EventBus eventBus,
      ActivityMapper mapper) {
    return new ActivityManager(mapper, eventBus);
  }

  @SuppressWarnings("deprecation")
  @Inject
  @Singleton
  @Provides
  PlaceController providePlaceController(EventBus eventBus) {
    return new PlaceController(eventBus);
  }

  @Inject
  @Provides
  MerchantServiceAsync provideMerchantService() {
    MerchantServiceAsync service = GWT.create(MerchantService.class);
    return service;
  }

  @Inject
  @Provides
  ConsumerServiceAsync provideConsumerService() {
    ConsumerServiceAsync service = GWT.create(ConsumerService.class);
    return service;
  }

  @Inject
  @Provides
  Resources provideResources() {
    return GWT.create(Resources.class);
  }

}
